package net.googlecode.morenko.task5;

import net.googlecode.morenko.task5.calculators.CalculatorFactory;
import net.googlecode.morenko.task5.workers.Director;
import net.googlecode.morenko.task5.workers.Employee;
import net.googlecode.morenko.task5.workers.Manager;
import net.googlecode.morenko.task5.workers.Worker;
import net.googlecode.morenko.task5.SortUtils;

import java.util.ArrayList;

/**
 * The main class.
 */
public class SalaryApp {

    public static ArrayList<Worker> workerList = new ArrayList<Worker>();
    /**
     * Creates manager without bonus.
     * @return reference on manager object.
     */
    public static Manager createManagerWithoutBonus() {
        Manager manager = new Manager("Ivan", "Ivanov", 7);
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(25);
        return manager;
    }

    /**
     * Creates manager with bonus.
     * @return reference on manager object.
     */
    public static Manager createManagerWithBonus() {
        Manager manager = new Manager("Petr", "Petrov", 2);
        manager.setAge(35);
        manager.setBonus(true);
        manager.setBonusAmount(1000);
        manager.setPerHour(false);
        manager.setRate(5000);
        return manager;
    }

    /**
     * Creates employee with bonus.
     * @return reference on employee object.
     */
    public static Employee createEmployeeWithBonus() {
        Employee employee = new Employee("Semen", "Semenov", 4);
        employee.setAge(55);
        employee.setBonus(true);
        employee.setBonusAmount(1500);
        employee.setPerHour(true);
        employee.setRate(8);
        employee.setExperience(10);
        return employee;
    }

    /**
     * Creates employee without bonus.
     * @return reference on employee object.
     */
    public static Employee createEmployeeWithoutBonus() {
        Employee employee = new Employee("Sergey", "Sergeev", 1);
        employee.setAge(45);
        employee.setBonus(true);
        employee.setPerHour(false);
        employee.setExperience(15);
        employee.setRate(200);
        return employee;
    }

    /**
     * Creates director.
     * @return reference on director object.
     */
    public static Director createDirector() {
        Director director = new Director("Pankrat", "Pankratovich",6);
        director.setAge(55);
        director.setBonusAmount(2000);
        director.setRate(35);
        return director;
    }

    /**
     * The main function of the program.
     * @param args command line arguments.
     */
    public static void main(String[] args) {
        workerList.add(createManagerWithBonus());
        workerList.add(createManagerWithoutBonus());
        workerList.add(createEmployeeWithBonus());
        workerList.add(createEmployeeWithoutBonus());
        workerList.add(createDirector());
        for (Worker x : workerList) {
            x.setSalary(CalculatorFactory.getCalculator(x).calculateSalary(x));
        }
        if (args[0].equalsIgnoreCase("code")) {
            SortUtils.printSortedByCode(workerList);
        }
        else if (args[0].equalsIgnoreCase("name")) {
            SortUtils.printSortedByLastName(workerList);
        }
        else if (args[0].equalsIgnoreCase("salary")) {
            SortUtils.printSortedBySalary(workerList);
        }
        else {
            System.out.println("You have written wrong parameter");
        }
    }
}
